package com.example.academicsystem.server.controller.admin;

import com.example.academicsystem.exception.InsertException;
import com.example.academicsystem.pojo.dto.GradeDeleteDto;
import com.example.academicsystem.pojo.dto.GradeDto;
import com.example.academicsystem.pojo.dto.GradeInsertDto;
import com.example.academicsystem.pojo.dto.GradeUpdateDto;
import com.example.academicsystem.result.PageResult;
import com.example.academicsystem.result.Result;
import com.example.academicsystem.server.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/grade")
@Slf4j
public class AdminGradeController {
    @Autowired
    private AdminService adminService;

    /**
     *分页查询grade （所有、根据courseId;
     * courseName;
     * studentId;
     * studentName;
     * teacherId;
     * teacherName;）
     * */
    @PostMapping("/page")
    public Result<PageResult> gradePageQuery(@RequestBody GradeDto gradeDto){
        log.info("gradePageQuery");
        PageResult pageResult = adminService.gradePageQuery(gradeDto);
        return Result.success(pageResult);
    }
    /**
     * 新增成绩
     * */
    @PostMapping("/insert")
    public Result gradeInsert(@RequestBody GradeInsertDto gradeInsertDto){
            log.info("gradeInsert");
            adminService.gradeInsert(gradeInsertDto);
            return Result.success();
    }
    /**
     * 删除成绩 by student-id and course_id
     * */
    @DeleteMapping("/delete")
    public Result gradeDelete(@RequestBody GradeDeleteDto gradeDeleteDto){
        log.info("gradeDelete:");
        adminService.gradeDelete(gradeDeleteDto);
        return Result.success();
    }
    /**
     * 修改成绩 by student—id and course_id
     * */
    @PutMapping("/update")
    public Result gradeUpdate(@RequestBody GradeUpdateDto gradeUpdateDto){
        log.info("gradeUpdate");
        adminService.gradeUpdate(gradeUpdateDto);
        return Result.success();
    }
}
